<template>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>房源管理</el-breadcrumb-item>
      <el-breadcrumb-item>审核列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <el-form :model="searchForm" class="demo-form-inline" >
        <el-form-item>
          <el-input style="width:150px;height:30px;" placeholder="房屋名称" v-model="searchForm.name"></el-input>
          <el-select   style="width:150px;height:30px; margin-left: 10px" v-model="searchForm.status" placeholder="选择状态">
            <el-option label="待审核" :value="0"></el-option>
            <el-option label="审核" :value="1"></el-option>
            <el-option label="成交" :value="2"></el-option>
          </el-select>
          <el-input style="width:150px;height:30px; margin-left: 10px"  placeholder="房屋地址" v-model="searchForm.addr"></el-input>
          <el-button @click="searchList" style="margin-left: 10px" plain type="info">搜索</el-button>
          <el-button @click="searchEmpty" plain type="info">清空</el-button>
        </el-form-item>
      </el-form>

      <el-table
        :data="houseList"
        stripe
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column
          label="房屋图片" width="120">
          <template slot-scope="scope">
            <img  v-if="scope.row.pic!=null" :src="'/api/house-charter/house/download/'+scope.row.pic" width="50px" height="50px">
          </template>
        </el-table-column>
        <el-table-column
          label="房屋名称"
          prop="name"
          width="120">
        </el-table-column>
        <el-table-column
          label="房屋地址"
          prop="addr"
          width="120">
        </el-table-column>
        <el-table-column
          label="房产证"
          width="120">
          <template slot-scope="scope">
            <img  v-if="scope.row.ppCard!=null" :src="'/api/house-charter/house/download/'+scope.row.ppCard" width="50px" height="50px">
          </template>
        </el-table-column>
        <el-table-column
          label="房东名字"
          prop="ownerName"
          width="120">
        </el-table-column>
        <el-table-column
          label="房东定价"
          width="120">
          <template slot-scope="scope">
            ${{scope.row.lprice}}
          </template>
        </el-table-column>
        <el-table-column
          label="中介定价"
          width="120">
          <template slot-scope="scope">
            ${{scope.row.dprice}}
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          prop="courseStatus"
          width="120">
          <template slot-scope="scope">
            {{scope.row.status | statusFit}}
          </template>
        </el-table-column>
        <el-table-column
          label="房子数量"
          prop="num"
          width="120">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-button @click="updateStatus(scope.row.id,1)" v-if="scope.row.status==0" size="small" type="text">审核通过</el-button>
            <el-button @click="getHouse(scope.row.id)" v-if="scope.row.status==0" size="small" type="text">定价</el-button>
            <el-button @click="delHouse(scope.row.id)" size="small" type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page.currentPage"
        :page-size="page.pageSize"
        :page-sizes="[5, 10, 20, 40]"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>

      <el-dialog  :append-to-body=true :close-on-click-modal="false" title="开始定价" :visible.sync="courseFormVisible"
                  @closed="crearUserForm"> <!--课程表单框 -->
        <el-form :rules="rules" ref="courseForm"  :model="courseForm">
          <el-form-item label="定价" label-width='120px' prop="dprice">
            <el-input-number v-model="courseForm.dprice" autocomplete="off"></el-input-number>
          </el-form-item>
        </el-form>
        <div class="dialog-footer" slot="footer">
          <el-button @click="courseFormVisible = false">取 消</el-button>
          <el-button @click="saveHouse" type="primary">确 定</el-button>
        </div>
      </el-dialog>

    </el-card>
  </div>
</template>

<script>
  export default {
    name: "intermediary",
    data() {
      return {
        houseList:[],
        searchForm: {},
        page: {
          currentPage: 0,
          pageSize: 5
        },
        total: 0,
        courseFormVisible: false,
        rules:{
          dprice: [{ required: true, message: '请输入定价金额' }, { type: 'number', message: '定金金额必须为数字值'}],
        },
        courseForm: {id:null,dprice:null},
        auth:{token:null},
        house:{}
      }
    },
    methods: {
      getHouse:function(id){//进行定价
        this.courseForm.id = id
        this.courseFormVisible = true
      },
      crearUserForm: function () {//清空数据
        this.courseForm = {}
      },
      saveHouse: function () { //课程保存
        debugger
        this.$refs['courseForm'].validate((valid) => {
          if (!valid) {
            return
          }
          this.$http.post("house-charter/house/saveHouse", this.courseForm).then((res) => {
            //如何提示
            if (res.data.success) {
              this.$message({
                message: res.data.message,
                type: 'success'
              })
            } else {
              this.$message.error(res.data.message)
            }
          })
          //关闭dialog框
          this.courseFormVisible = false
          //重新加载列表
          this.searchList()
        })
      },
      delHouse: function (id) {//删除课程
        this.$http.get("house-charter/house/deleteHouse/" + id).then((res) => {
          if (res.data.success) {
            this.$message({message: res.data.message, type: 'success'})
            //重新加载列表
            this.searchList()
          } else {
            this.$message.error(res.data.message)
          }
        })
      },
      updateStatus: function (id,val) {//审核通过
        this.house.status = val
        this.$http.post("house-charter/house/updateStatus/" + id, this.house).then((res) => {
          if (res.data.success) {
            this.$message({message: res.data.message, type: 'success'})
            //重新加载列表
            this.searchList()
          } else {
            this.$message.error(res.data.message)
          }

        })
      },
      searchEmpty: function () {//清空
        this.searchForm = {}
      },
      handleSizeChange: function (val) {
        this.page.pageSize = val
        this.searchList()
      },
      handleCurrentChange: function (val) {
        this.page.currentPage = val
        this.searchList()
      },
      searchList: function () {//房源列表
        this.$http.post("house-charter/house/list/" + this.page.currentPage + "/" + this.page.pageSize, this.searchForm).then((res) => {
          this.houseList = res.data.result.list
          this.total = res.data.result.total
        })
      }
      },
      filters: {
        statusFit:function(val){
          if(val==0) return "待审核"
          if(val==1) return "审核"
          if(val==2) return "成交"
        }

      },
      mounted() {
        this.searchList()//列表展示
      }
    }
</script>

<style scoped>

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
